<template>
  <el-input v-if="type === 'input'" v-model="inputValue" clearable />
  <el-select v-if="type === 'select'" v-model="inputValue" clearable>
    <el-option v-for="option in options" :key="option.label" :label="option.label" :value="option.value" />
  </el-select>
</template>

<script lang="ts">
import { defineComponent, ref, watch } from 'vue'
export default defineComponent({
  name: 'FreeInput',
  props: {
    modelValue: [String, Number, Boolean],
    type: {
      type: String,
      default: 'input',
    },
    options: Array,
  },
  emits: ['update:modelValue'],
  setup(props, context) {
    const inputValue = ref(props.modelValue)

    watch(inputValue, () => {
      context.emit('update:modelValue', inputValue.value)
    })

    return {
      inputValue,
    }
  },
  watch: {
    modelValue(val) {
      this.inputValue = val
    },
  },
})
</script>

<style lang="scss" scoped></style>
